package com.hmall.search.web;

import com.hmall.common.dto.PageDTO;
import com.hmall.search.pojo.ItemDoc;
import com.hmall.search.pojo.R;
import com.hmall.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/search")
public class SearchController {

    @Autowired
    private SearchService searchService;

    @PostMapping("/list")
    public PageDTO<ItemDoc> page(@RequestBody R r) throws IOException {

        return searchService.page(r);
    }


    @GetMapping("/suggestion")
    public List<String> getSuggestion(@RequestParam("key") String key) throws IOException {
        List<String> suggestion = searchService.getSuggestion(key);
        return suggestion;
    }

    @PostMapping("/filters")
    public Map<String,List<String>> getFilters(@RequestBody R r) throws IOException {

        return searchService.getFilters(r);
    }



}
